<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<script type="module">

    let a = [1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 3, 4, 4, 4, 4, 2, 3, 3, 3, 3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 5, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2];

    let result = [];

    for (let i = 0; i < a.length; i++) {
        getBiggerOneLevel(a, a[i], i);
    }

    function getBiggerOneLevel(all, root, index) {
        let childList = [];
        for (let i = index + 1; i < all.length; i++) {
            let bean = all[i];
            if (bean - root == 1) {
                childList.push(bean);
            } else{
                break;
            }
        }
        console.log('index:', index, 'parent:', root, 'child:', childList);
    }


</script>

<body>

</body>
</html>